package com.example.demo.controller;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/login")
    public boolean login(HttpServletRequest request, String username, String password){
        boolean ret = false;
        if (StringUtils.hasLength(username) && StringUtils.hasLength(password)){
            if (username.equals("admin") && password.equals("admin")){
                HttpSession session = request.getSession();
                session.setAttribute("userinfo","userinfo");
                return true;
            }
        }
        return ret;
    }

    @RequestMapping("/index")
    public String index(){
//        int num = 10 / 0;
        Object object = null;
        System.out.println(object.hashCode());
        return "Hello,Index.";
    }
}
